package com.huika.renrench.control.main.shoptf.adap;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.huika.lib.utils.MoneyShowTool;
import com.huika.lib.utils.StringUtils;
import com.huika.renrench.GlobalApp;
import com.huika.renrench.R;
import com.huika.renrench.control.common.base.BaseAda;
import com.huika.renrench.support.bean.ShopTransferListBean;

/**
 * @author chenyuan
 * @date：2015年6月2,下午2:15:30
 * @describe:店铺转让详情adapter
 */
public class ShopTranferAdapter extends BaseAda<ShopTransferListBean> {

	/**
	 * @param context
	 */
	public ShopTranferAdapter(Context context) {
		super(context);
		// TODO Auto-generated constructor stub

	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		// View view = null;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.item_shop_tranfer, parent,
					false);
			holder = new ViewHolder();

			holder.iv_img = (ImageView) convertView.findViewById(R.id.iv_img);
			holder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
			holder.tv_address = (TextView) convertView
					.findViewById(R.id.tv_address);
			holder.tv_price = (TextView) convertView
					.findViewById(R.id.tv_price);
			holder.tv_distance = (TextView) convertView
					.findViewById(R.id.tv_distance);
			holder.tv_area = (TextView) convertView.findViewById(R.id.tv_area);
			convertView.setTag(holder);

		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		setDataFromNet(holder, position);

		return convertView;
	}

	/**
	 * @author cy
	 * @date 2015年6月2日,下午3:48:47
	 * @param holder
	 * @param position
	 */
	private void setDataFromNet(ViewHolder holder, int position) {
		// TODO Auto-generated method stub
		ShopTransferListBean item = getItem(position);
		holder.tv_name.setText(item.shopName);
		// holder.tv_price.setText("学费￥："
		// + MoneyShowTool.nolastDF(item.tradePrice));
		if(!item.price.equals("面议")) {
			if (item.getPrice().equals("0")||item.getPrice()==null||item.getPrice().equals("null")) {
				holder.tv_price.setText("￥面议");
			}else{
				holder.tv_price.setText("￥" + StringUtils.getWan(Double.parseDouble(item.price)));
			}
		} else {
			holder.tv_price.setText("￥" + item.price);
		}
		holder.tv_address.setText("临近：" + item.nearby);
		if (GlobalApp.getInstance().isLocated()) {
			holder.tv_distance.setVisibility(View.VISIBLE);
			holder.tv_distance.setText(item.getDistance());
		}else{
			holder.tv_distance.setVisibility(View.GONE);	
		}
		
		
		holder.tv_area.setText("面积：" + item.getAcreage()+"㎡");
		GlobalApp.loadImgLoader(holder.iv_img, item.defaultImage);
	}

	private class ViewHolder {
		public ImageView iv_img;
		public TextView tv_name, tv_address, tv_price, tv_distance, tv_area;
	}
}
